//
//  CALayer+Category.swift
//  cxd4iphone
//
//  Created by hexy on 12/25/15.
//  Copyright © 2015 hexy. All rights reserved.
//

import UIKit

extension CALayer {
    
    func shake() {
        
        let kfa = CAKeyframeAnimation(keyPath: "transform.translation.x")
        
        let s = 5
        kfa.values = [-s, 0, s, 0, -s, 0, s, 0]
        kfa.duration = 0.3
        kfa.repeatCount = 2
        kfa.removedOnCompletion = true
        
        self.addAnimation(kfa, forKey: "shake")
    }
}

//CAKeyframeAnimation *kfa = [CAKeyframeAnimation animationWithKeyPath:@"transform.translation.x"];
//
//CGFloat s = 5;
//
//kfa.values = @[@(-s),@(0),@(s),@(0),@(-s),@(0),@(s),@(0)];
//
////时长
//kfa.duration = 0.3f;
//
////重复
//kfa.repeatCount = 2;
//
////移除
//kfa.removedOnCompletion = YES;
//
//[self addAnimation:kfa forKey:@"shake"];
